package com.zzg.springboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zzg.springboot.dao.UserRepository;
import com.zzg.springboot.entity.UserEntity;

@Controller
@RequestMapping("/api/springboot")
public class UserController {
	@Autowired
	private UserRepository dao;

	@RequestMapping(value = "/one", method = { RequestMethod.GET })
	public void one() {
		UserEntity entity = new UserEntity();
		entity.setAge(27);
		entity.setId("1");
		entity.setName("zzg");
		dao.save(entity);
	}

	@RequestMapping(value = "/two", method = { RequestMethod.GET })
	@ResponseBody
	public List<UserEntity> two() {
		return dao.findAll();
	}
	
	@RequestMapping(value = "/three", method = { RequestMethod.GET })
	@ResponseBody
	public UserEntity three() {
		return dao.findOne("1");
	}

}
